package com.mebs.edi.model.edi;

import java.sql.Time;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import com.mebs.edi.model.dom.DomAttribute;
import com.mebs.edi.model.dom.DomChildren;
import com.mebs.edi.model.dom.DomEntity;


/**
 * 
 * GS + GE sections of a EDI file 
 * 
 * @author nit
 *
 */
@Entity()
@Table(name = "edi_gs")
@DomEntity(name = "GS")
public class EdiGs {
	
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "Id")
	private Long id;
	
	@OneToMany(cascade=CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinColumn(name="gs_id")
	@DomChildren
	private List<EdiSt> stSections;
	
	@Column(nullable = true, length = 2)
	@DomAttribute
	private String gs01; 	// Functional ID Code
	
	@Column(nullable = true, length = 15)
	@DomAttribute
	private String gs02; 	// Application Sender's Code
	
	@Column(nullable = true, length = 15)
	@DomAttribute
	private String gs03; 	// Application Receiver's Code
	
	@Column(nullable = true)
	@DomAttribute
	private Date gs04; 	// Group Date
	
	@Column(nullable = true)
	@DomAttribute
	private Time gs05; 	// Group Time
	
	@Column(nullable = true)
	@DomAttribute
	private Long gs06; 	// Group Control No.
	
	@Column(nullable = true, length = 2)
	@DomAttribute
	private String gs07; 	// Responsible Agency Code
	
	@Column(nullable = true, length = 12)
	@DomAttribute
	private String gs08; 	// Version/Release Indicator Identifier
	
	@Column(nullable = true)
	@DomAttribute
	private Integer ge01; 	// Number of Transaction Sets Included
	
	@Column(nullable = true)
	@DomAttribute
	private Long ge02; 	// Group Control Number
	
	public EdiGs() {
		super();
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getGs01() {
		return gs01;
	}

	public void setGs01(String gs01) {
		this.gs01 = gs01;
	}

	public String getGs02() {
		return gs02;
	}

	public void setGs02(String gs02) {
		this.gs02 = gs02;
	}

	public String getGs03() {
		return gs03;
	}

	public void setGs03(String gs03) {
		this.gs03 = gs03;
	}

	public Date getGs04() {
		return gs04;
	}

	public void setGs04(Date gs04) {
		this.gs04 = gs04;
	}

	public Time getGs05() {
		return gs05;
	}

	public void setGs05(Time gs05) {
		this.gs05 = gs05;
	}

	public Long getGs06() {
		return gs06;
	}

	public void setGs06(Long gs06) {
		this.gs06 = gs06;
	}

	public String getGs07() {
		return gs07;
	}

	public void setGs07(String gs07) {
		this.gs07 = gs07;
	}

	public String getGs08() {
		return gs08;
	}

	public void setGs08(String gs08) {
		this.gs08 = gs08;
	}

	public Integer getGe01() {
		return ge01;
	}

	public void setGe01(Integer ge01) {
		this.ge01 = ge01;
	}

	public Long getGe02() {
		return ge02;
	}

	public void setGe02(Long ge02) {
		this.ge02 = ge02;
	}

	public List<EdiSt> getStSections() {
		return stSections;
	}

	public void setStSections(List<EdiSt> stSections) {
		this.stSections = stSections;
	}

	@Override
	public String toString() {
		return "EdiGs [id=" + id + ", stSections=" + stSections + ", gs01=" + gs01 + ", gs02=" + gs02
				+ ", gs03=" + gs03 + ", gs04=" + gs04 + ", gs05=" + gs05 + ", gs06=" + gs06 + ", gs07="
				+ gs07 + ", gs08=" + gs08 + ", ge01=" + ge01 + ", ge02=" + ge02 + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((ge01 == null) ? 0 : ge01.hashCode());
		result = prime * result + ((ge02 == null) ? 0 : ge02.hashCode());
		result = prime * result + ((gs01 == null) ? 0 : gs01.hashCode());
		result = prime * result + ((gs02 == null) ? 0 : gs02.hashCode());
		result = prime * result + ((gs03 == null) ? 0 : gs03.hashCode());
		result = prime * result + ((gs04 == null) ? 0 : gs04.hashCode());
		result = prime * result + ((gs05 == null) ? 0 : gs05.hashCode());
		result = prime * result + ((gs06 == null) ? 0 : gs06.hashCode());
		result = prime * result + ((gs07 == null) ? 0 : gs07.hashCode());
		result = prime * result + ((gs08 == null) ? 0 : gs08.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((stSections == null) ? 0 : stSections.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		EdiGs other = (EdiGs) obj;
		if (ge01 == null) {
			if (other.ge01 != null)
				return false;
		} else if (!ge01.equals(other.ge01))
			return false;
		if (ge02 == null) {
			if (other.ge02 != null)
				return false;
		} else if (!ge02.equals(other.ge02))
			return false;
		if (gs01 == null) {
			if (other.gs01 != null)
				return false;
		} else if (!gs01.equals(other.gs01))
			return false;
		if (gs02 == null) {
			if (other.gs02 != null)
				return false;
		} else if (!gs02.equals(other.gs02))
			return false;
		if (gs03 == null) {
			if (other.gs03 != null)
				return false;
		} else if (!gs03.equals(other.gs03))
			return false;
		if (gs04 == null) {
			if (other.gs04 != null)
				return false;
		} else if (!gs04.equals(other.gs04))
			return false;
		if (gs05 == null) {
			if (other.gs05 != null)
				return false;
		} else if (!gs05.equals(other.gs05))
			return false;
		if (gs06 == null) {
			if (other.gs06 != null)
				return false;
		} else if (!gs06.equals(other.gs06))
			return false;
		if (gs07 == null) {
			if (other.gs07 != null)
				return false;
		} else if (!gs07.equals(other.gs07))
			return false;
		if (gs08 == null) {
			if (other.gs08 != null)
				return false;
		} else if (!gs08.equals(other.gs08))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (stSections == null) {
			if (other.stSections != null)
				return false;
		} else if (!stSections.equals(other.stSections))
			return false;
		return true;
	}
}
